/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package generadorva;

import DistLib.poisson;

/**
 *
 * @author USUARIO
 */
public class Poisson {

    private double k;

    public Poisson(double k) {
        this.k = k;
    }

    public double getK() {
        return k;
    }

    public void setK(double k) {
        this.k = k;
    }

    /*
     *
     * 
     */
    public int generate(double u){
        int x = 0;
        double p = Math.exp(-1*k);
        double Fx = p;
        while (u > Fx) {
            x++;
            p = p*k/x;
            Fx += p;
        }
        return x;
    }
    public static void main(String[] args) {
        Poisson poisson = new Poisson(10);
        System.out.println(poisson.generate(0.34567D));
        poisson p = new poisson();
        System.out.println("2 = " + p.cumulative(2, 10));
        System.out.println("3 = " + p.cumulative(3, 10));
        System.out.println("4 = " + p.cumulative(4, 10));
        System.out.println("5 = " + p.cumulative(5, 10));
        System.out.println("8 = " + p.cumulative(8, 10));
        System.out.println("9 = " + p.cumulative(9, 10));
        System.out.println("10 = " + p.cumulative(10, 10));
        System.out.println("20 = " + p.cumulative(20, 10));
        
        
    }

}
